﻿using System;
using System.Xml.Linq;

namespace IocPerformance.Adapters
{
    public abstract class ContainerAdapterBase : IContainerAdapter
    {
        public virtual string Version
        {
            get
            {
                var document = XDocument.Load("packages.config");
                var elements = document.Root.Elements();
                foreach (var element in elements)
                {
                    if (element.Attribute("id").Value == PackageName)
                        return element.Attribute("version").Value;
                }
                return "unknown";
            }
        }

        public abstract string PackageName
        {
            get;
        }

        public virtual bool SupportsInterception
        {
            get { return false; }
        }

        public virtual bool SupportsConditional
        {
            get { return false; }
        }

        public virtual bool SupportGeneric
        {
            get { return false; }
        }

        public virtual bool SupportsMultiple
        {
            get { return false; }
        }

        public abstract void Prepare();

        public abstract object Resolve(Type type);

        public virtual TService Resolve<TService>() where TService : class
        {
            return default(TService);
        }

        public virtual object ResolveProxy(Type type)
        {
            return this.Resolve(type);
        }

        public abstract void Dispose();
    }
}